home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Programming / Source / winterp-1.13 / examples / subprocess.lsp < prev    next >
Encoding:
Lisp/Scheme  |  1991-10-06  |  4.3 KB  |  155 lines

  1. ; -*-Lisp-*-
  2. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3. ;
  4. ; File:         subprocess.lsp
  5. ; RCS:          $Header: subprocess.lsp,v 1.3 91/10/05 19:02:39 mayer Exp $
  6. ; Description:  Demo of spawning an interactive subprocess and interacting
  7. ;        with the subrpocess through XT_ADD_INPUT. Subprocess can be
  8. ;        off doing a long calculation while WINTERP GUI remains active.
  9. ;            Subprocesses and XT_ADD_INPUT only available in WINTERP 1.14...
  10. ; Author:       Niels Mayer, HPLabs
  11. ; Created:      Sat Oct  5 18:58:46 1991
  12. ; Modified:     Sat Oct  5 19:02:32 1991 (Niels Mayer) mayer@hplnpm
  13. ; Language:     Lisp
  14. ; Package:      N/A
  15. ; Status:       X11r5 contrib tape release
  16. ;
  17. ; WINTERP Copyright 1989, 1990, 1991 Hewlett-Packard Company (by Niels Mayer).
  18. ; XLISP version 2.1, Copyright (c) 1989, by David Betz.
  19. ;
  20. ; Permission to use, copy, modify, distribute, and sell this software and its
  21. ; documentation for any purpose is hereby granted without fee, provided that
  22. ; the above copyright notice appear in all copies and that both that
  23. ; copyright notice and this permission notice appear in supporting
  24. ; documentation, and that the name of Hewlett-Packard and Niels Mayer not be
  25. ; used in advertising or publicity pertaining to distribution of the software
  26. ; without specific, written prior permission.  Hewlett-Packard and Niels Mayer
  27. ; makes no representations about the suitability of this software for any
  28. ; purpose.  It is provided "as is" without express or implied warranty.
  29. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  30.  
  31.  
  32.  
  33. (setq f1 (exp_spawn "bc" "bc"))
  34. (let ((line NIL))
  35.   (setq input-cb1
  36.     (xt_add_input f1
  37.               :read
  38.               '(
  39.             (let ((c (read-char FDINPUTCB_FILE)))
  40.               (cond
  41.                ((char= c #\newline) 
  42.                 (terpri)
  43.                 (mapcar 'princ (reverse line))
  44.                 (terpri)
  45.                 (setq line nil)
  46.                 )
  47.                (t
  48.                 (setq line (cons c line))
  49.                 ))
  50.               ))))
  51.   )
  52.  
  53. ; (load "rc-shell")
  54. ; (let ((line NIL))
  55. ;   (setq input-cb1
  56. ;     (xt_add_input f1
  57. ;               :read
  58. ;               '(
  59. ;             (let ((c (read-char FDINPUTCB_FILE)))
  60. ;               (cond
  61. ;                ((char= c #\newline) 
  62. ;                 (send XM_PUSH_BUTTON_WIDGET_CLASS :new :managed
  63. ;                   rc_w
  64. ;                   :xmn_label_string
  65. ;                   (format nil "~A" (reverse line)))
  66. ;                 (setq line nil)
  67. ;                 )
  68. ;                (t
  69. ;                 (setq line (cons c line))
  70. ;                 ))
  71. ;               ))))
  72. ;   )
  73.  
  74.  
  75. (format f1 "scale=10\n")
  76. (format f1 "731 / 223\n")
  77.  
  78. ;(xt_remove_input input-cb1)
  79. ;(xt_add_input input-cb1)
  80.  
  81. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  82.  
  83. (setq f2 (exp_popen "bc"))
  84. (let ((line NIL))
  85.   (setq input-cb2
  86.     (xt_add_input f2
  87.               :read
  88.               '(
  89.             (let ((c (read-char FDINPUTCB_FILE)))
  90.               (cond
  91.                ((char= c #\newline) 
  92.                 (terpri)
  93.                 (mapcar 'princ (reverse line))
  94.                 (terpri)
  95.                 (setq line nil)
  96.                 )
  97.                (t
  98.                 (setq line (cons c line))
  99.                 ))
  100.               ))))
  101.   )
  102.  
  103. (format f2 "scale=2\n")
  104. (format f2 "731 / 223\n")
  105.  
  106. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  107.  
  108. ;;;
  109. ;;; must call xt_remove_input before closing file, otherwise you get
  110. ;;; jillions of "error: X Toolkit Warning: Select failed; error code 9"
  111. ;;;
  112.  
  113. (input_active_p input-cb1)
  114. (xt_remove_input input-cb1)
  115. (input_active_p input-cb1)
  116. (close f1)
  117. (exp_wait)
  118.  
  119. ;;;
  120. ;;; must call xt_remove_input before closing file, otherwise you get
  121. ;;; jillions of "error: X Toolkit Warning: Select failed; error code 9"
  122. ;;;
  123. (xt_remove_input input-cb2)
  124. (input_active_p input-cb2)
  125. (close f2)
  126. (exp_wait)
  127.  
  128. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  129.  
  130. (setq bc_proc_io (exp_spawn "bc" "bc"))
  131.  
  132. (load "rc-shell")            ;'rc_w' is now a XmRowColumn layout manager.
  133.  
  134. (let ((line NIL))            ;'line' is part of callback's func closure.
  135.   (setq input-cb1
  136.     (xt_add_input       ;add an input callback whenever data readable
  137.      '(           ;FDINPUTCB_FILE is locally bound inside inputcb
  138.        (let ((c (read-char FDINPUTCB_FILE))) ;read a single char
  139.          (cond
  140.           ((char= c #\newline)    ;if at end of line, make a label
  141.            (send XM_LABEL_WIDGET_CLASS :new :managed rc_w
  142.              :XMN_LABEL_STRING (format nil "~A" (reverse line)))
  143.            (setq line nil)        ;and clear line
  144.            )
  145.           (t            ;else prepend char to line
  146.            (setq line (cons c line)) 
  147.            )))
  148.        )
  149.      ))
  150.   )
  151.  
  152. (format bc_proc_io "scale=10\n")
  153.  
  154. (format bc_proc_io "731 / 223\n")
  155.